from django.shortcuts import render

# Create your views here.
from rest_framework.views import APIView
from settings import PRIVATE_KEY_PATH, ALIPAY_KEY_PATH, PUBLICE_KEY_PATH
from utils.alipay import AliPay


class AlipayView(APIView):
    def get(self, request):
        """
        处理支付宝return_url
        """
        pass

    def post(self, request):
        """
        处理支付宝的notify_url
        """
        processed_dict = {}
        for key, value in request.POST.items():
            processed_dict[key] = value

        sign = processed_dict.pop("sign", None)

        alipay = AliPay(
            appid="2016091400509592",
            app_notify_url="http://45.40.193.155:8000/alipay/return",
            app_private_key_path=PRIVATE_KEY_PATH,
            alipay_public_key_path=ALIPAY_KEY_PATH,  # 支付宝的公钥，验证支付宝回传消息使用，不是你自己的公钥,
            debug=True,  # 默认False,
            return_url="http://45.40.193.155:8000/alipay/return"
        )

        verify_re = alipay.verify(processed_dict, sign)

        pass


